package com.zl.customer.web;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * TODO
 * @ClassName: TestServlet
 * @author: suke
 * @since: 2021/8/2 9:59
 */
@WebServlet(name="TestServlet",urlPatterns = "/Test")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.得到Application域对象  是ServletContext类的对象   this.getServletContext()
        ApplicationContext applicationContext = (ApplicationContext)this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
       // System.out.println(applicationContext);
        //System.out.println(applicationContext.getBean("dataSource"));

        System.out.println(applicationContext.getBean(LoginServlet.class));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
}
